package com.example.imtoken.modules.main

import com.blankj.utilcode.util.BusUtils
import com.example.imtoken.R
import com.example.imtoken.core.base.BaseFragment
import com.example.imtoken.core.utils.BusConfig
import com.example.imtoken.databinding.MainFragmentBinding
import kotlinx.android.synthetic.main.main_fragment.*

class MainFragment :
    BaseFragment<MainFragmentViewModel, MainFragmentBinding>(MainFragmentViewModel::class.java) {

    override fun initLayoutId(): Int {
        return R.layout.main_fragment
    }

    override fun init() {
        mainViewPager2.adapter = MainFragmentAdapter(childFragmentManager, lifecycle)
        mainViewPager2.offscreenPageLimit = 1
        mainViewPager2.setCurrentItem(0, false)
        mainViewPager2.isUserInputEnabled = false
        bottomNavigationView.setOnNavigationItemSelectedListener {
            when (it.itemId) {
                R.id.walletFragment -> {
                    BusUtils.postSticky(BusConfig.page_index_sticky_main_activity,0)
                    mainViewPager2.setCurrentItem(0, false)
                }
                R.id.browseFragment -> {
                    BusUtils.postSticky(BusConfig.page_index_sticky_main_activity,1)
                    mainViewPager2.setCurrentItem(1, false)
                }
                R.id.myFragment -> {
                    BusUtils.postSticky(BusConfig.page_index_sticky_main_activity,2)
                    mainViewPager2.setCurrentItem(2, false)
                }
            }
            true
        }
    }

}